package com.baoleme.baoleme_goods_service.service.impl;

import com.baoleme.baoleme_goods_service.mapper.CategoryMapper;
import com.baoleme.baoleme_goods_service.service.CategoryService;
import com.baoleme_goods_model.dto.CategoryDTO;
import com.baoleme_goods_model.entity.Category;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wuyunbin
 * @since 2024-09-13
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    @Override
    public boolean updateCategory(CategoryDTO categoryDTO) {
        Category category = new Category();
        category.setId(categoryDTO.getId());
        category.setName(categoryDTO.getName());
        category.setSort(categoryDTO.getSort());
        category.setType(categoryDTO.getType());
        return this.updateById(category);
    }

    @Override
    public boolean updateStatus(String id, String status) {
        Category category = new Category();
        category.setId(id);
        category.setStatus(Integer.parseInt(status));
        return this.updateById(category);
    }

    @Override
    public boolean saveCategory(CategoryDTO categoryDTO) {
        Category category = new Category();
        category.setId(categoryDTO.getId());
        category.setName(categoryDTO.getName());
        category.setSort(categoryDTO.getSort());
        category.setType(categoryDTO.getType());
        return this.save(category);
    }
}
